package com.lz.code.zkcurator.config;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liuzhi
 * @description
 * @date 2022/3/6 13:36
 */
@Configuration
public class CuratorConfig {

    private final CuratorWrapper curatorWrapper;

    public CuratorConfig (CuratorWrapper curatorWrapper) {
        this.curatorWrapper = curatorWrapper;
    }

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework () {
        return CuratorFrameworkFactory.newClient(
                curatorWrapper.getConnectString(),
                curatorWrapper.getSessionTimeoutMs(),
                curatorWrapper.getConnectionTimeoutMs(),
                new RetryNTimes(curatorWrapper.getRetryCount(),curatorWrapper.getElapsedTimeMs())
        );
    }

}
